<template>
  <div>
    <ZgDialog ref="dialog" title="默认归档配置" width="70%" height="500px" @ok="onOk" >
      <div class="flx-b">
        <div class="source table mr40">
          <a-table
            style="margin-top:40px;"
            :columns="columnSource"
            :data-source="sourceFeild"
            :row-selection="{
              onChange:changeSource,
            }"
          />
        </div>
        <div class="target table">
          <ZgSelect modelVal="gdtable1" class="mb10" :options="GDTableType" @change="changeGDTable()"></ZgSelect>
          <a-table
            :columns="columnSource"
            :data-source="GDFeild"
            :row-selection="{
              onChange:changeSource,
            }"
          />
        </div>
      </div>

    </ZgDialog>
  </div>
</template>
<script>

export default {
  data () {
    return {
      sourceFeild: [],
      GDTableType: [],
      GDFeild: [],
      columnSource: [
        {
          title: '字段编码',
          dataIndex: 'COLUMN_NAME',
          key: 'COLUMN_NAME'
        },
        {
          title: '字段名称',
          dataIndex: 'COMMENTS',
          key: 'COMMENTS'
        },
        {
          title: '表名',
          dataIndex: 'TABLE_NAME',
          key: 'TABLE_NAME'
        }
      ]
    }
  },
  methods: {
    changeSource() {},
    open (param) {
      this.$refs.dialog.open()
      this.getSourceTableField(param.obj)
    },
    // 查询原表 字段
    getSourceTableField(obj) {
      const param = {
        columnName: '', // 查询条件：字段名
        comments: '', // 查询条件：字段注释
        formType: obj.value, // 必传：表单类型
        queryFlag: '1'// 必传:查询原表还是归档表,1-原表，2-归档表
      }
      this.$http.post('/swan-cloud-settle-its/intellectFormManage/selectFormAndChildAllColumn', param).then(res => {
        if (res.code === 200) {
          this.sourceFeild = res.data.mainTableColumns
        }
      })
    },
    getGDTypeList() {
      this.$http.post('/swan-cloud-settle-its/intellectFormManage/getGdFormTypeDict').then(res => {
        // this.GDTableType = [
        //   { label: '归档1', value: 'gdtable1' },
        //   { label: '归档2', value: 'gdtable12' },
        //   { label: '归档3', value: 'gdtable3' },
        //   { label: '归档4', value: 'gdtable4' },
        //   { label: '归档5', value: 'gdtable5' },
        //   { label: '归档6', value: 'gdtable6' }
        // ]
        if (res.code === 200) {
          this.GDTableType = res.data
        }
      })
    },
    changeGDTable(val) {
      console.log('val', val)
      const param = {
        columnName: '', // 查询条件：字段名
        comments: '', // 查询条件：字段注释
        formType: val, // 必传：表单类型
        queryFlag: '2'// 必传:查询原表还是归档表,1-原表，2-归档表
      }
      this.$http.post('/swan-cloud-settle-its/intellectFormManage/selectFormAndChildAllColumn', param).then(res => {
        // this.GDFeild = [
        //   { label: '归档字段名称', value: 'columnName1' },
        //   { label: '归档字段名称', value: 'columnName2' },
        //   { label: '归档字段名称', value: 'columnName3' },
        //   { label: '归档字段名称', value: 'columnName4' },
        //   { label: '归档字段名称', value: 'columnName5' },
        //   { label: '归档字段名称', value: 'columnName6' }
        // ]
        // if (res.code === 1) {
        //   this.sourceFeild = res.data
        // }
      })
    },
    onOk() {
    },
  },
  created() {
    // 查询归档表类型
    this.getGDTypeList()
  }
}
</script>

<style lang="scss"  scoped>
.table{
  flex:1
}
</style>
